package com.base.myproject.server;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.base.myproject.server.database.PoolMan;


public class Login {
    public static boolean login(String username ,String password) {
        
        PoolMan pm = new PoolMan();
        Connection con = null;

        ResultSet rs1 = null;
        try {
            con = pm.getPool("test");
            if (username.equals("root")) {
            	rs1 = pm.executeQuery("SELECT count(*) num FROM bcode where bcode = '"+username+"' and password='"+password+"'");
            } else {
            	rs1 = pm.executeQuery("SELECT count(*) num FROM bcode,bcode_job where bcode.bcode = bcode_job.bcode and bcode_job.employstatus = '在职" +
                		"' and bcode.bcode = '"+username+"' and password='"+password+"'");
            }
			rs1.next();

			if (rs1.getString("num").equals("0")) {
				return false;
			} else
				return true;
        } catch (SQLException ex) {
            ex.printStackTrace();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        finally
        {
        	pm.release();
        }
        
        return false;
    }
    
 public static boolean Ccodelogin(String username ,String password) {
        
	 	if(username.indexOf("%")>0 || password.indexOf("%")>0)
	 		return false;
        PoolMan pm = new PoolMan();
        Connection con = null;

        ResultSet rs1 = null;
        try {
            con = pm.getPool("test");
            
            rs1 = pm.executeQuery("SELECT count(*) num FROM ccode	 where loginname = '"+username+"' and password='"+password+"'");
            rs1.next();
               
                if(rs1.getString("num").equals("0"))
                {
                    return false;
                }
                else
                    return true;
        } catch (SQLException ex) {
            ex.printStackTrace();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        finally
        {
        	pm.release();
        }
        
        return false;
    }
    
}
